from flask import Blueprint,request,jsonify
from db import db1
from utils.comm import get_data

from utils.acl import acl
from utils.redisconn import r
from utils.jwttoken import token1

bp_adminuser = Blueprint('adminuser',__name__)

@bp_adminuser.route("/login",methods=['POST'])
def fgmylogin():
    data = get_data()
    sql = "select * from userss where name='%s'and password='%s'"%(data['name'],data['password'])
    res = db1.find(sql)
    if res:
        vurl = acl.get_page_reslist(res["id"])
        print(vurl)
        key = "interface"+str(res["id"])
        r.insert_values(key,vurl)
        token = token1.encode_jwt(int(res["id"]),60*60,"123")
        return jsonify({"code":200,"userid":res["id"],"token":token,"vurl":vurl,'name':res['name']})
    else:
        return jsonify({"code":400,"msg":'错误'})




